<style>
[v-cloak]{display:none}
</style>
<div class="form-inline">
    <div class="form-group">
        <input type="month" class="form-control" id="mont" value="<?php echo yii::$app->request->get('m')?yii::$app->request->get('m'):date('Y-m');?>" />
        <select class="form-control" id="saleman">
            <option value=0>--选择业务员--</option>
            <?php foreach($this->params['staff_list'] as $v):?>
            <option value=<?php echo $v['job_number'];?> <?php if(yii::$app->request->get('saleman')==$v['job_number']){echo 'selected';};?>><?php echo $v['name'];?></option>
            <?php endforeach;?>
        </select>
        <button class="btn btn-sucess" onclick="Page.change_month()">搜索</button>
    </div>
</div>
<br/>
<div class="col-lg-7 col-xs-7 col-sm-7 col-md-7">
    <b>编制单位：义乌市兢赛电子商务有限公司</b>
    <b style="margin-left:50%">单位：元</b>
    <table class="table table-borderd">
        <thead>
            <tr>
                <th style="width:50px">id</th>
                <th>采购编号</th>
                <th>操作员</th>
                <th>产品</th>
                <th>订单金额</th>
                <th>已付金额</th>
                <th>未付金额</th>
                <th>是否结算提成</th>
            </tr>
        </thead>
        <tbody v-cloak>
            <tr v-for="(v,k) in list">
                <td>{{k+1}}</td>
                <td>{{v.purchase_order}}</td>
                <td>{{v.name}}</td>
                <td>{{v.product}}</td>
                <td>{{v.need_pay}}</td>
                <td>{{v.have_pay}}</td>
                <td>{{(v.need_pay-v.have_pay).toFixed(2)}}</td>
                <td>
                    <select v-model="v.status" class="form-control" style="border:none;padding:0px;width:100%;margin:0px" @change="change(v.purchase_order,v.status)">
                        <option value=1>未结提成</option>
                        <option value=2>以结提成</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>统计</td>
                <td colspan=3></td>
                <td>{{total_need_pay}}</td>
                <td>{{total_have_pay}}</td>
                <td>{{(total_need_pay-total_have_pay).toFixed(2)}}</td>
                <td></td>
            </tr>
        </tbody>
    </table>
</div>

<script>
    Page.change_month=function(){
        var saleman = $("#saleman").val();
        var m = $("#mont").val();
        window.location.href="/table/finance?type=<?php echo $_GET['type']??4;?>&m="+m+"&saleman="+saleman;
    }
    new Vue({
        el: "#main",
        data: {
            total_have_pay:<?php echo $this->params['total']['total_have_pay'];?>,
            total_need_pay:<?php echo $this->params['total']['total_need_pay'];?>,
            list: <?php echo json_encode($this->params['list']);?>
        },
        methods:{
            change:function(order,status){
               layer.confirm('确认修改',{},function(){
                   $.post("/table/purchase_order_update",{order:order,status:status},function(res){
                       if(res.code==1) {
                           layer.confirm(res.msg,{},function(){
                                window.location.reload();
                           })
                       }else{
                           layer.alert(res.msg);
                       }
                   },'json')
               })
            }
        }
    })
</script>